package com.tjw.ec.upms.controller;

import com.tjw.ec.common.core.util.PageUtils;
import com.tjw.ec.common.core.util.R;
import com.tjw.ec.upms.api.dto.PermitVO;
import com.tjw.ec.upms.api.entity.PermitEntity;
import com.tjw.ec.upms.service.PermitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 控制动作层： 由tb_Module与tb_Action两表结合产生的系统基本权限表;
 *
 * @author T-junwen
 * @email t-junwen@foxmail.com
 * @date 2019-07-27 17:28:58
 */
@RestController
@RequestMapping("permit")
public class PermitController {

    @Autowired
    private PermitService permitService;


    /**
     * @Title: 根据用户编号获取用户权限
     * @Param: [userId]
     * @return: com.tjw.ec.common.core.util.R
     * @Author: 田俊文
     * @Date: 2019/8/2 15:03
     * @Throws:
     */
    @GetMapping("/getPermitByUserId/{userId}")
    public R  getPermitByUserId(@PathVariable("userId")String userId){
        List<PermitVO> permits =  permitService.getPermitByUserId(userId);
        return R.data(permits);
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = permitService.queryPage(params);
        return R.data(page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{permitId}")
    public R info(@PathVariable("permitId") String permitId) {
            PermitEntity permit = permitService.getById(permitId);
        return R.data(permit);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody PermitEntity permit) {
            permitService.save(permit);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody PermitEntity permit) {
            permitService.updateById(permit);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestParam String[]ids) {
            permitService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
